﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_DAL;
using Zor_Tools;

namespace Zor_Bll
{

    /// <summary>
    /// 单元信息
    ///  create by Guoph at 2017.3.27
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BuildingBrowse_Bll<T> where T : class
    {

        /// <summary>
        /// 获取楼宇信息列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(dynamic Model, int index, out int TotalCount,string where)
        {
            int Dtid = RequestSession.GetSessionUser().DT_Id;
            int Isadmin = RequestSession.GetSessionUser().Is_Admin;
            var sqlSurch = " 1=1 ";
            if (Isadmin == 1 || Dtid == 16)
            {
                sqlSurch = " 1=1 ";
            }
            else
            {
                sqlSurch = " (StreetOfficeID = " + Dtid + " or Dt_ParentId = " + Dtid + ")";
            }
            if (Model.StreetOffice != null)
            {
                sqlSurch += " and " + " StreetOffice like '%" + Model.StreetOffice + "%'  ";
            }
            if (Model.Community != null)
            {
                sqlSurch += " and " + " Community like '%" + Model.Community + "%'  ";
            }
            if (Model.Bd_Name != null)
            {
                sqlSurch += " and " + " Bd_Name like '%" + Model.Bd_Name + "%'  ";
            }
            if (Model.Bd_Aname != null)
            {
                sqlSurch += " and " + " Bd_Aname like '%" + Model.Bd_Aname + "%'  ";
            }
            if (Model.Bd_CreateDate != null)
            {
                int state = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Bd_CreateDate + " 00:00:00").ToString()));
                int end = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Bd_CreateDate + " 23:59:59").ToString()));
                sqlSurch += " and " + " Bd_CreateDate >= " + state + " and Bd_CreateDate<= " + end + " ";
                
            }

            return PagerHelp<T>.GetPagerList(index, "V_BuildingBrowse", "Community", out TotalCount, sqlSurch);
        }
    }
}
